package com.caesar.exer2;

/**
 * @author caesar
 * @date 2025/7/16
 * @Description:
 * @apiNote
 */
public class Employee implements Comparable<Employee>{
    private int id;
    private String name;
    private double salary;
    private int age;

    public Employee(int id, String name, double salary, int age) {
        super();
        this.id = id;
        this.name = name;
        this.salary = salary;
        this.age = age;
    }
    public Employee() {
        super();
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public double getSalary() {
        return salary;
    }
    public void setSalary(double salary) {
        this.salary = salary;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Employee [id = " + id + ",name=" + name + ", salary=" + salary + ", age=" + age + "]";
    }

    //重写抽象方法，按照薪资比较大小，薪资相同的按照姓名的自然顺序比较大小。
    @Override
    public int compareTo(Employee o) {
        int result = Double.compare(this.salary, o.salary);
        if(result == 0){
            result = this.id - o.id;
        }
        return result;
    }

}

